package com.beermanager.activities;

import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.View;
import com.doffman.dragarea.DragShadowBuilder;

/**
 * User: paulo
 * Date: 6/29/12
 * Time: 10:09 AM
 */
public class DrawableDragShadowBuilder implements DragShadowBuilder
{
    private View mView;
    private Drawable mDrawable;
    private Point mTouchPoint;

    public DrawableDragShadowBuilder(View view, Drawable drawable, Point touchPoint)
    {
        mView = view;
        mDrawable = drawable;
        mTouchPoint = touchPoint;
    }

    @Override
    public View getView()
    {
        return mView;
    }

    @Override
    public void onProvideShadowMetrics(Point shadowSize, Point touchPoint)
    {
        shadowSize.x = mDrawable.getIntrinsicWidth();
        shadowSize.y = mDrawable.getIntrinsicHeight();

        touchPoint.x = mTouchPoint.x;
        touchPoint.y = mTouchPoint.y;

        mDrawable.setBounds(new Rect(0, 0, shadowSize.x, shadowSize.y));
    }

    @Override
    public void onDraw(Canvas canvas)
    {
        mDrawable.draw(canvas);
    }
}